package com.spica.platform.base.exception.errorcode;

import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum LockRtnCodEnum implements IErrorCode {
    LOCK_NULL_ERROR("BASE_LOCK_00001", "DistributedLock is null"),
    LOCK_KEY_NULL_ERROR("BASE_LOCK_00002", "lockKey is null"),
    LOCK_TIME_OUT_ERROR("BASE_LOCK_00003", "锁等待超时"),
    UN_KNOWN_LOCK_ERROR("BASE_LOCK_00000", "未知锁异常"),
    LOCK_ERROR("BASE_LOCK_00004", "requires RLock type"),
    ;
    private String rtnCod;
    private String rtnMsg;

    LockRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    };
    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(LockRtnCodEnum.values())
                .filter(lockRtnCodEnum -> StringUtil.equals(lockRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(LockRtnCodEnum.UN_KNOWN_LOCK_ERROR);
    }
}
